# automatic compilation of C++ source files of the test
# this source file was modified, so it is a good time to check if it  ; \
# has new header files dependencies                                   ; \

$(00_dir_dev_test)/%.o : $(qt_test_hs) $(00_dir_dev_test)/%.$(coc_source_extension)
	$(00_show) ""                                                            ; \
	echo  "---------------------------------------- "                     ; \
	echo  "Compiling $<"                                                  ; \
        $(coc_compile_command) $(01_final_test_inc_dir) $(01_compile_flags) $(01_final_test_minus_d) $< -o $@ 


# automatic regeneration of header code files from qt-designer '.ui' files
$(00_dir_dev_test)/%.$(coc_header_extension): $(00_dir_dev_test)/%.ui
	$(00_show) ""                                                            ; \
	echo  "---------------------------------------- "                     ; \
	echo  "Generating $@ from  $<"                                        ; \
	uic $< -o $@                                                          ; 


# automatic regeneration of source test files from qt-designer '.ui' files
#$(00_dir_dev_code)/test/%.$(coc_source_extension): $(00_dir_dev_code)/test/%.ui
#	$(00_show) ""                                                            ; \
#	echo  "---------------------------------------- "                     ; \
#	echo  "Generating $@ from  $<"                                       ; \
#	echo  "NOT IMPLEMENTED"                                              ; \
#	touch $@                                                             ;
#	uic -impl $(00_dir_dev_code)/test/$*.$(coc_header_extension) $< -o $@


# builds the test as a program
test_build_pgm: 
	$(00_show) ""                                                           ; \
	echo "Building a test program for $(00_project)"                             ; \
	$(coc_program_command) $(coc_program_prefix)$(00_project)_test$(coc_program_sufix)    \
		$(01_test_objs) $(01_final_test_static_libs)                         \
                $(01_final_prj_lib_dir) $(01_final_prj_shared_libs)                  \
		$(01_final_test_lib_dir) $(01_final_test_shared_libs)                \
		$(coc_search_lib_dir)                                            ; \
	mv $(coc_program_prefix)$(00_project)_test$(coc_program_sufix) $(00_dir_product_bin)         \
                    2> /dev/null                                             ;  


#                           PUBLIC

#@public@|test_clean|Cleans the Test of the Project
#@public_detailed@|test_clean|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] test_clean
#@public_detailed@|test_clean|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|test_clean|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.
test_clean : 
	$(00_show) ""                                                                       ; \
	echo "********************************************* "                            ; \
	echo "Cleaning test for $(00_project)"                                              ; \
	rm -f $(00_dir_dev_test)/*.o  2> /dev/null                                               ; \
	rm -f $(00_dir_dev_test)/*~ 2> /dev/null                                                 ; \
	rm -f $(00_dir_dev_test)/*.d 2> /dev/null                                                ; \
	rm -f $(00_dir_product_bin)/$(coc_program_prefix)$(00_project)_test$(coc_program_sufix) 2> /dev/null   ; 


# 01_setup

#@public@|test_compile|Compiles the Test of the Project
#@public_detailed@|test_compile|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] test_compile
#@public_detailed@|test_compile|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|test_compile|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.
test_compile : 01_setup $(01_test_objs)



#@public@|test_build|Builds the Test of the Project
#@public_detailed@|test_build|Syntax: 'make project=<project-name> [coc=<cpu-os-compiler>] [verbose=0/1]  [target=debug/release] test_build
#@public_detailed@|test_build|Where <project-name> is an existing project. Please rum 'make prj_list' to list all the avaiable projects.
#@public_detailed@|test_build|Where <cpu-os-compiler> is the name of a file that contain definitions for a CPU, OS and compiler. Please, run 'make coc_list' to list all the combinations avaiables.

# 01_setup 
test_build : code_build_chain test_compile
	$(00_show) ""                                                         ; \
	echo "********************************************* "                 ; \
	echo "Builing test for  $(00_project)"                                ; \
	$(00_make_cmd) -s test_build_pgm                                      ; 

test_build_chain:
	$(00_show) ""                                                         ; \
	echo "**************************************** "                      ; \
	echo -n "Building the code of all Projects that $(00_project) "       ; \
	echo "depend on"                                                      ; \
	$(00_make_cmd) 01_test_chain chain_target=test_build                  ; \
	$(00_make_cmd) test_build                                             ;




#@public@|test_create|Creates a header file for a Test of the Project
#@public_detailed@|test_create|Syntax: 'common-cmd-syntax test_create class_name=<class-to-be-tested>'
#@public_detailed@|test_create|describe-common-parameters
#@public_detailed@|test_create|Where <test-name> is the name of the test, which will be the name of the header file.
test_create: 01_setup
	$(00_show) ""                                                         ; \
	echo "********************************************* "                 ; \
	echo "Creating test for '$(class_name)' for  $(00_project)"           ; \
	class_tester="$(class_name)_tester"                                   ; \
	test_name_file=$$class_tester".h"                                     ; \
	cd $(00_dir_dev_test)                                                 ; \
	client=`echo $(00_project) | cut -d '.' -f 1`                         ; \
	project=`echo $(00_project) | cut -d '.' -f 2`                        ; \
	group=`echo $(00_project) | cut -d '.' -f 3`                          ; \
	guard="__"$$client"_"$$project"_"$$group                              ; \
	runtest_file="runtest.h"                                              ; \
	if [ ! -f $$runtest_file ]; then                                        \
		echo "#ifndef "$$guard"_runtest_h__" > $$runtest_file         ; \
		echo "#define "$$guard"_runtest_h__" >> $$runtest_file        ; \
		echo "" >> $$runtest_file                                     ; \
		echo "#define runtest(t) std::cout << (t ? std::string(#t) + std::string(\" PASSED\") : std::string(#t) + std::string(\" FAILED\")) << std::endl"  >> $$runtest_file ; \
		echo ""      >> $$runtest_file                                ; \
		echo "#endif" >> $$runtest_file                               ; \
	fi                                                                    ; \
	if [ ! -f $$test_name_file ]; then                                      \
		echo "#ifndef "$$guard"_"$$class_tester"_h__" > $$test_name_file ; \
		echo "#define "$$guard"_"$$class_tester"_h__" >> $$test_name_file ; \
		echo ""  >> $$test_name_file                                  ; \
		echo "#include <iostream>" >> $$test_name_file                ; \
		echo "#include <cstdint>" >> $$test_name_file                 ; \
		echo "#include <string>" >> $$test_name_file                  ; \
		echo ""  >> $$test_name_file                                  ; \
		echo "#include \""$$runtest_file"\"" >> $$test_name_file      ; \
		echo ""  >> $$test_name_file                                  ; \
		echo "#include <"$(00_project)"/"$(class_name)".h>"  >> $$test_name_file ; \
		echo ""  >> $$test_name_file                                  ; \
		echo "namespace "$$client" {" >> $$test_name_file             ; \
		echo "    namespace "$$project" {" >> $$test_name_file        ; \
		echo "        namespace "$$group" {" >> $$test_name_file      ; \
		echo ""  >> $$test_name_file                                  ; \
		echo "            class "$$class_tester" {"  >> $$test_name_file ; \
		echo ""  >> $$test_name_file                                  ; \
                echo "            public:" >> $$test_name_file                ; \
		echo "                static void run() {" >> $$test_name_file ; \
		echo "                }" >> $$test_name_file                  ; \
		echo ""  >> $$test_name_file                                  ; \
		echo "            };" >> $$test_name_file                     ; \
		echo ""  >> $$test_name_file                                  ; \
		echo "        }" >> $$test_name_file                          ; \
		echo "    }" >> $$test_name_file                              ; \
		echo "}" >> $$test_name_file                                  ; \
		echo "" >> $$test_name_file                                   ; \
		echo "#endif" >> $$test_name_file                             ; \
	fi                                                                    ; 




-include $(00_dir_dev_test)/*.d


